package com.suneast.suneaststore.modules.shopcart.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.shopcart.ShopGoodsListBean;

import java.util.List;

/**
 * Created by zestz on 2018/3/7.
 */

public class ItemBillAdapter extends BaseQuickAdapter<ShopGoodsListBean.GoodsBean, ItemBillAdapter.ViewHolder> {


    public ItemBillAdapter(int layoutResId, @Nullable List<ShopGoodsListBean.GoodsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(ViewHolder helper, ShopGoodsListBean.GoodsBean item) {
        Glide.with(helper.itemView.getContext()).load(item.getThumb()).into((ImageView) helper.getView(R.id.img_goods));
        helper.setText(R.id.tv_goods_name, item.getTitle())
                .setText(R.id.tv_goods_specs, item.getOption_title())
                .setText(R.id.tv_goods_count, "" + item.getTotal());
        String goodsPriceTv = "￥" + String.format("%.2f", item.getPrice())
                + (item.getDiscount() > 0 ? "+" + String.format("%.2f", item.getDiscount()) + "帘邦豆" : "");
        helper.setText(R.id.tv_goods_price, goodsPriceTv);
        TextView widthHeightTv = helper.getView(R.id.tv_goods_size);
        if (item.getHeight() != 0 && item.getWidth() != 0) {
            widthHeightTv.setVisibility(View.VISIBLE);
            widthHeightTv.setText(String.format(helper.itemView.getContext()
                            .getResources().getString(R.string.width_height),
                    String.format("%.2f", item.getWidth()),
                    String.format("%.2f", item.getHeight())));
        } else {
            widthHeightTv.setVisibility(View.INVISIBLE);
        }
    }

    public class ViewHolder extends BaseViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
